<?php

namespace App\Admin\Controllers;

use App\Admin\Metrics\Examples;
use App\Http\Controllers\Controller;
use Dcat\Admin\Controllers\AdminController;
use Dcat\Admin\Controllers\Dashboard;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Illuminate\Support\Facades\URL;

class BaseArticleController extends AdminController
{
    public $categoryId = 0;

    public function __construct(){
        $url = URL::full();
        preg_match('/service_article\/([\s\S]*?)\/manage/', $url, $urlData);
        $this->categoryId = $urlData[1];
    }

    public function index(Content $content)
    {
        return $content
            ->header('文章管理')
            ->description('列表')
            ->breadcrumb('文章管理')
            ->body($this->grid());
    }

    public function create(Content $content)
    {
        return $content
            ->header('文章管理')
            ->description('列表')
            ->breadcrumb('文章管理')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    public function grid()
    {
        return ArticleController::grid($this->categoryId);
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    public function form()
    {
        return ArticleController::form($this->categoryId);
    }
}
